@bg: #fff;
@fg: #333;

html,
body {
  width: 100%;
  // height: 100%;
}

.scrollbar-style {
  &::-webkit-scrollbar {
    width: 8px;
  }
  &::-webkit-scrollbar-track {
    // -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
    border-radius: 10px;
    background-color: transparent;
  }
  &::-webkit-scrollbar-thumb {
    border-radius: 5px; // -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);
    background-color: rgba(150, 150, 150, 0.66);
    border: 4px solid rgba(150, 150, 150, 0.66);
    background-clip: content-box;
  }
}

.crossnote {
  .scrollbar-style();
}

// the preview
.preview-container {
  width: 100%;
  margin: 0;
  padding: 0;
  box-sizing: border-box;

  ul {
    list-style: disc;
  }

  ol {
    list-style: decimal;
  }

  &.show-sidebar-toc {
    .md-sidebar-toc {
      font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans,
        sans-serif;
      position: fixed;
      top: 0;
      right: 0;
      width: 268px;
      height: 100%;
      padding: 32px 0;
      overflow: auto;
      background-color: @bg;
      // color: @fg;
      font-size: 14px;
      box-shadow: -4px 0px 12px rgba(150, 150, 150, 0.33);
      box-sizing: border-box;

      a {
        // color: @fg;
        text-decoration: none;
      }

      .md-toc {
        padding: 0 16px;

        .md-toc-link-wrapper {
          .md-toc-link {
            display: inline;
            padding: 0.25rem 0;

            p,
            div {
              display: inline;
            }
          }

          &.highlighted {
            .md-toc-link {
              font-weight: 800;
            }
          }
        }
      }
    }
    .crossnote {
      width: calc(~'100% - 268px');
    }
  }

  .crossnote[data-for='preview'] {
    left: 0;
    top: 0;
    margin: 0; // z-index: 999;
    padding: 2em;
    overflow: auto;
    display: block;
    box-sizing: border-box;
    position: relative;

    // code chunk
    .code-chunk {
      position: relative;

      /*
            .output-div {
                overflow-x: auto;

                svg {
                    display: block;
                }
            }
            */

      pre {
        cursor: text;
      }

      .code-chunk-btn-group {
        position: absolute;
        right: 28px;
        top: 0;
        display: none;

        .run-btn,
        .run-all-btn {
          float: right;
          margin-left: 4px;
          min-width: 38px;

          &:hover {
            cursor: pointer;
          }
        }
      }

      &:hover {
        .code-chunk-btn-group {
          display: block;
        }
      }

      .status {
        position: absolute;
        right: 0;
        top: 0;
        font-size: 0.85em;
        color: inherit;
        padding: 2px 6px;
        background-color: rgba(0, 0, 0, 0.04);
        display: none;
      }

      &.running {
        .code-chunk-btn-group {
          display: none;
        }
        .status {
          display: block;
        }
      }
    }

    // highlight
    .highlight-line {
      position: relative;

      &.highlight-active {
        box-shadow: 0 0px 2px 1px #95c258;
        border-radius: 6px;
      }
    }

    /*
        // NOTE: This will cause margin error on elements like `<pre>`
        [data-source-line] {
          margin: 0;
        }
        */
  }
}

body[data-presentation-mode] {
  .crossnote[data-for='preview'] {
    padding: 0 !important;
    width: 100%;
    height: 100%;
  }

  // As in-preview editor doesn't work well for the
  // presentation mode, we hide it for now.
  .final-line.end-of-document {
    display: none;
  }

  // hide both topbar and footer
  .topbar,
  .footer {
    display: none;
  }
}

body:not([data-presentation-mode]) {
  .crossnote[data-for='preview'] {
    height: auto;
  }

  .final-line.end-of-document {
    margin-top: 64px !important;
    margin-bottom: 64px !important;
    padding: 8px;
    color: #bbb;
    cursor: pointer;

    &::before {
      content: 'End of document';
    }
  }

  .crossnote.zen-mode {
    .final-line.end-of-document {
      display: none;
    }
  }

  &[data-preview-theme='dark'] {
    .final-line.end-of-document {
      color: #555;
    }
  }
}

.monaco-line-decoration {
  background: rgb(112, 162, 42);
  width: 5px !important;
  margin-left: 3px;
}

body.floating-action-open.preview-container {
  .code-chunk {
    .code-chunk-btn-group,
    .status {
      display: none !important;
    }
  }
}

.highlight-element-being-edited {
  // Hide all children elements except the one has class name `.markdown-editor`
  & > *:not(.markdown-editor) {
    visibility: hidden;
    max-width: 100%;
  }
}

// https://github.com/shd101wyy/vscode-markdown-preview-enhanced/issues/1920
// it seems like tailwindcss overrides the `table` style.
pre span.token.table {
  display: inline;
}
